package com.stylefeng.guns.modular.stream.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.warpper.StreamWarpper;
import com.stylefeng.guns.modular.system.warpper.UserWarpper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Stream;
import com.stylefeng.guns.modular.stream.service.IStreamService;

import java.util.List;
import java.util.Map;

/**
 * 视频流管理控制器
 *
 * @author fengshuonan
 * @Date 2018-07-28 21:17:00
 */
@Controller
@RequestMapping("/stream")
public class StreamController extends BaseController {

    private String PREFIX = "/stream/stream/";

    @Autowired
    private IStreamService streamService;

    /**
     * 跳转到视频流管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "stream.html";
    }

    /**
     * 跳转到添加视频流管理
     */
    @RequestMapping("/stream_add")
    public String streamAdd() {
        return PREFIX + "stream_add.html";
    }

    /**
     * 跳转到修改视频流管理
     */
    @RequestMapping("/stream_update/{streamId}")
    public String streamUpdate(@PathVariable Integer streamId, Model model) {
        Stream stream = streamService.selectById(streamId);
        model.addAttribute("item",stream);
        LogObjectHolder.me().set(stream);
        return PREFIX + "stream_edit.html";
    }

    /**
     * 获取视频流管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<Map<String, Object>> streams = streamService.selectStreams(null);
        Object warp = new StreamWarpper(streams).warp();
        return warp;
    }

    /**
     * 新增视频流管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Stream stream) {
        streamService.insert(stream);
        return SUCCESS_TIP;
    }

    /**
     * 删除视频流管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer streamId) {
        streamService.deleteById(streamId);
        return SUCCESS_TIP;
    }

    /**
     * 修改视频流管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Stream stream) {
        streamService.updateById(stream);
        return SUCCESS_TIP;
    }

    /**
     * 视频流管理详情
     */
    @RequestMapping(value = "/detail/{streamId}")
    @ResponseBody
    public Object detail(@PathVariable("streamId") Integer streamId) {
        return streamService.selectById(streamId);
    }
}
